package com.pp.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pp.entity.User;
import com.pp.mapper.UserMapper;
import com.pp.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanou on 18/2/27.
 */
@Service
public class UserServiceImpl implements UserService{

    @Resource
    private UserMapper userMapper;

    @Override
    public boolean findUser(User user) {
        User user1 = userMapper.findUser(user);
        if(StringUtils.isEmpty(user1)){
            return false;
        }
        return true;
    }
    @Override
    public PageInfo findAllUser(int pageNum) {
        PageHelper.startPage(pageNum,4);
        List<User> users = new ArrayList<>();
        users = userMapper.findAllUser();
        PageInfo pageInfo = new PageInfo(users);
        return pageInfo;
    }

    @Override
    public void delete(User user) {
        userMapper.delete(user);
    }

    @Override
    public User updateUser(User user) {
        User user1 = userMapper.updateUser(user);
        return user1;
    }

    @Override
    public void upUser(User user, int id) {
        userMapper.upUser(user,id);
    }
}
